package com.free.semantic.core.impl.demo;

import com.free.semantic.common.Ls;
import com.free.semantic.common.RelationChain;
import com.free.semantic.core.ConceptInstanceManage;
import com.free.semantic.core.ConceptManage;
import com.free.semantic.core.impl.BaseTest;
import com.free.semantic.core.impl.ConceptInstanceManageImpl;
import com.free.semantic.req.RelationDefineGroup;
import com.free.semantic.utils.Utils;

import java.util.List;


public class Demo9_realScene extends BaseTest {

    /**
     * 消除维度的case
     */
    public void test() {

        ConceptManage modelOne;
        ConceptManage modelTwo;

        ConceptInstanceManage instanceOne;
        ConceptInstanceManage modelInstanceTwo;

        ConceptManage modelInterface;
        {
            /**
             * 创建第一个语义模型
             */
            RelationDefineGroup group = new RelationDefineGroup();
            // relation 包含(A,B)
            defineRelation(group, "找到一个",
                    defineItem(oneObj("A"), oneObj("B")));

            defineRelation(group, "找到多个",
                    defineItem(oneObj("A"), moreObj("B")));


            //  使用包含关系 定义一个语义网络
            modelOne = getConceptManage(group);
            //object 省份 城市
            object(modelOne, "日程1", "开始时间1", "结束时间1", "主题1", "参会人1", "人1");
            instanceOne = new ConceptInstanceManageImpl(modelOne);

            //包含(省份,城市)
            createRelationWithFunction(instanceOne, "找到一个", "日程1", "开始时间1", emptyFunction());
            createRelationWithFunction(instanceOne, "找到一个", "日程1", "结束时间1", emptyFunction());
            createRelationWithFunction(instanceOne, "找到一个", "日程1", "主题1", emptyFunction());
            createRelationWithFunction(instanceOne, "找到多个", "日程1", "参会人1", emptyFunction());
            createRelationWithFunction(instanceOne, "找到一个", "参会人1", "人1", emptyFunction());
            createRelationWithFunction(instanceOne, "找到多个", "人1", "日程1", emptyFunction());

            List<RelationChain> chains = modelOne.findAllRelationChain(Ls.of("人1"), "日程1");

            List<RelationChain> chains2 = modelOne.findAllRelationChain(Ls.of("日程1"), "人1");

            List<RelationChain> chains3 = modelOne.findAllRelationChain(Ls.of("人1"), "参会人1");


        }

        {
            /**
             * 创建第一个语义模型
             */
            RelationDefineGroup group = new RelationDefineGroup();
            // relation 包含(A,B)
            defineRelation(group, "找到一个",
                    defineItem(oneObj("A"), oneObj("B")));

            defineRelation(group, "找到多个",
                    defineItem(oneObj("A"), moreObj("B")));

            //  使用包含关系 定义一个语义网络
            modelTwo = getConceptManage(group);
            //object 省份 城市
            object(modelTwo, "日程2", "开始时间2", "结束时间2", "主题2", "参会人2", "人2");
            //包含(省份,城市)
            createRelation(modelTwo, "找到一个", "日程2", "开始时间2");
            createRelation(modelTwo, "找到一个", "日程2", "结束时间2");
            createRelation(modelTwo, "找到一个", "日程2", "主题2");
            createRelation(modelTwo, "找到多个", "日程2", "参会人2");
            createRelation(modelTwo, "找到一个", "参会人2", "人2");

            createRelation(modelTwo, "找到多个", "人2", "日程2");

            //创建模型的一个实现，并且实现 省份查询城市  和  城市查询 省份 函数（添加一些测试数据）
            modelInstanceTwo = new ConceptInstanceManageImpl(modelTwo);
        }


        {
            /**
             * 创建第一个语义模型
             */
            RelationDefineGroup group = new RelationDefineGroup();
            // relation 包含(A,B)
            defineRelation(group, "找到一个",
                    defineItem(oneObj("A", "B"), oneObj("C")));

            defineRelation(group, "找到多个",
                    defineItem(oneObj("A", "B"), moreObj("C")));

            //  使用包含关系 定义一个语义网络
            modelInterface = getConceptManage(group);
            //object 省份 城市
            object(modelInterface, "日程", "开始时间", "结束时间", "主题", "软件来源");
            //包含(省份,城市)
            createRelation2(modelInterface, "找到一个", "日程", "软件来源", "开始时间");
            createRelation2(modelInterface, "找到一个", "日程", "软件来源", "结束时间");
            createRelation2(modelInterface, "找到一个", "日程", "软件来源", "主题");

            ConceptInstanceManageImpl modelInstanceInterface = new ConceptInstanceManageImpl(modelInterface);

            ConceptInstanceManage copy = Utils.copy(instanceOne);

            Utils.mergerConcept(copy, modelInstanceInterface);

            Utils.equalConceptMap(copy, Ls.of(""), "", Ls.of(""), "");

        }

        System.out.println(modelOne);
    }


    /**
     * 增加维度的case
     */
    public void test2() {


        ConceptManage modelOne;

        ConceptManage modelTwo;

        ConceptInstanceManage modelInstanceOne;

        ConceptInstanceManage modelInstanceTwo;

        ConceptManage modelInterface;

        {
            /**
             * 创建第一个语义模型
             */
            RelationDefineGroup group = new RelationDefineGroup();
            // relation 包含(A,B)
            defineRelation(group, "找到一个",
                    defineItem(oneObj("A"), oneObj("B")));

            defineRelation(group, "找到多个",
                    defineItem(oneObj("A"), moreObj("B")));


            //  使用包含关系 定义一个语义网络
            modelOne = getConceptManage(group);
            //object 省份 城市
            object(modelOne, "人", "体重");
            //包含(省份,城市)
            createRelation(modelOne, "找到一个", "人", "体重");
            //创建模型的一个实现，并且实现 省份查询城市  和  城市查询 省份 函数（添加一些测试数据）
            modelInstanceOne = new ConceptInstanceManageImpl(modelOne);
        }

        {
            /**
             * 创建第一个语义模型
             */
            RelationDefineGroup group = new RelationDefineGroup();
            // relation 包含(A,B)
            defineRelation(group, "找到一个",
                    defineItem(oneObj("A", "B"), oneObj("C")));

            defineRelation(group, "找到多个",
                    defineItem(oneObj("A", "B"), moreObj("C")));

            //  使用包含关系 定义一个语义网络
            modelInterface = getConceptManage(group);
            //object 省份 城市
            object(modelInterface, "人1", "时间1", "体重1");
            //包含(省份,城市)
            createRelation2(modelInterface, "找到一个", "人1", "时间1", "体重1");

            ConceptInstanceManageImpl modelInstanceInterface = new ConceptInstanceManageImpl(modelInterface);

        }
    }


}
